﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using Jxym.wlkc2011.Module.CMS.MODEL;
using Jxym.wlkc2011.Module.CMS.Public;

namespace Jxym.wlkc2011.WebSite
{
    public partial class contentType : System.Web.UI.UserControl
    {
        private int _menuId = 0;
        private string html;
        private string _siteName;
        public string Html
        {
            get { return html; }
        }

        private MsSqlDal<Cms_ContentClass> ccc = new MsSqlDal<Cms_ContentClass>();

        protected void Page_Load(object sender, EventArgs e)
        {
            html = "";
            if (!IsPostBack)
            {
                if (Request.Params["m"] != null)
                {
                    _menuId = Convert.ToInt32(Request.Params["m"]);
                }
                if (Request.Params["siteName"] != null)
                {
                    _siteName = Request.Params["siteName"];
                }

                Cms_ContentClass cccinfo = ccc.GetModel(_menuId);
                IList<Cms_ContentClass> cccList = ccc.GetList("ParentID=" + _menuId, null, "Sort ASC", 0);
                cmsPublic cp = new cmsPublic();
                if (cccinfo != null && cccList.Count > 0)
                {
                    this.html += "<div class=\"mainListBox fl mr10 mb10 width223\"><h1 class=\"main_title\"><span class=\"h1_l\"></span><span class=\"h1_c\">" + cccinfo.Title + "</span><span class=\"h1_r\"></span></h1><div class=\"main_list\">";
                    treeStr = "";
                    Tree(_menuId, _menuId.ToString());
                    this.html += treeStr;
                    this.html += "</div></div><div class=\"clear\"></div>";
                }
            }
        }

        string treeStr = "";

        private void Tree(int menuId, string url)
        {
            IList<Cms_ContentClass> cccList = ccc.GetList("ParentID=" + menuId, null, "Sort ASC", 0);

            if (cccList.Count > 0)
            {
                treeStr += "<ul>";

                int i = 0;

                foreach (Cms_ContentClass info in cccList)
                {
                    if (i == 0)
                    {
                        url = url + "_" + info.ID;
                    }
                    else
                    {
                        string[] urls = url.Split('_');
                        string url2 = "";
                        for (int j = 0; j < urls.Length - 1; j++)
                        {
                            url2 += urls[j] + "_";
                        }
                        url = url2 + info.ID;
                    }
                    treeStr += "<li><a href=\"" + _siteName + "_m" + url + ".xhtml\" title='" + info.Title + "'>" + (info.Title.Length > 13 ? info.Title.Substring(0, 12) + ".." : info.Title) + "</a>";
                    Tree(info.ID, url);
                    i++;
                    treeStr += "</li>";
                }

                url = menuId + "_" + url;

                treeStr += "</ul>";
            }
        }
    }
}